home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-01-22 | 7.5 KB | 286 lines | [TEXT/ALFA] |
-
- # The menu.
- menu -n $tclMenu -p tclMenuProc {
- "/Z<O<UtraceTclProc╔"
- "/D<O<UdumpTraces"
- "(-"
- "rebuildTclIndices"
- "(-"
- "<U/PprocDefinition"
- "getVarValue╔"
- }
- proc tclMenu {} {}
-
- newModeVar Tcl prefixString {# } 0
- newModeVar Tcl wordWrap {0} 1
- newModeVar Tcl funcExpr {^proc *([+-a-zA-Z0-9]+)} 0
- newModeVar Tcl wordBreak {(\$)?[a-zA-Z0-9_]+} 0
- newModeVar Tcl wordBreakPreface {([^a-zA-Z0-9_\$]|.\$)} 0
- newModeVar Tcl elecLBrace 1 1
- newModeVar Tcl elecRBrace 1 1
- newModeVar Tcl elecReturn 1 1
- newModeVar Tcl autoMark 0 1
- newModeVar Tcl electricTab 1 1
- newModeVar Tcl stringColor green 0
- newModeVar Tcl commentColor red 0
- newModeVar Tcl keywordColor blue 0
-
- set tclKeyWords {
- then append array break case catch cd close concat continue elseif else eof
- error eval exec exit expr file flush foreach format for gets global glob
- history if incr info join lappend library lindex linsert list llength
- lrange lreplace lsearch lsort open pid proc puts pwd read regexp regsub
- rename return scancontext scan seek set source split string switch tell
- time trace unknown unset uplevel upvar while
-
- menu
- }
- if {[info exists Tclwords]} {set tclKeyWords [concat $tclKeyWords $Tclwords]}
- regModeKeywords -e {#} -c $TclmodeVars(commentColor) -k $TclmodeVars(keywordColor) Tcl $tclKeyWords -s $TclmodeVars(stringColor)
- unset tclKeyWords
-
- #================================================================================
-
- proc electricTclLeft {} {
- global TclmodeVars
-
- if { [isSelection] } { deleteSelection }
- if { [literalChar] } { insertText "\{"; return }
- set pat {\}[ \t\r]*(else(if)?)[ \t\r]*}
- if { !$TclmodeVars(elecLBrace) || \
- (([lookAt [getPos]] != "\r") && ([getPos] != [maxPos])) || \
- [catch {search -s -f 0 -r 1 "\}" [getPos]} res] || \
- ![regexp $pat [getText [lindex $res 0] [getPos]] dum word] } {
- insertText "\{"
- return
- }
- replaceText [lindex $res 0] [getPos] "\} $word \{\r"
- indentLine
- if { $word == "elseif" } {
- previousLine
- endOfLine
- }
- }
- bind '\{' <s> electricTclLeft Tcl
-
-
- proc electricTclRight {} {
- global TclmodeVars
-
- if { [isSelection] } { deleteSelection }
- if { [literalChar] } { insertText "\}"; return }
- if { !$TclmodeVars(elecRBrace) || \
- [regexp {[^ \t]} [getText [lineStart [getPos]] [getPos]]] } {
- insertText "\}"
- blink [matchIt "\}" [expr [getPos] - 2]]
- return
- }
- set start [lineStart [getPos]]
- insertText "\}"
- backwardChar
- indentLine
- endOfLine
- tclCarriageReturn
- blink [matchIt "\}" $start]
- }
- bind '\}' <s> electricTclRight Tcl
-
-
- proc tclCarriageReturn {} {
- global TclmodeVars
-
- insertText "\r"
- if {$TclmodeVars(elecReturn)} {
- indentLine
- }
- }
- bind '\r' tclCarriageReturn Tcl
-
-
-
- proc rebuildTclIndices {} {
- global auto_path
- set d [pwd]
- # do we really need the next line? Alpha's original uses it.
- cd
- foreach dir $auto_path {
- # if directory exists
- if { ![catch { cd $dir } ] } {
- # if there are any files
- if { ![catch { glob *.*tcl } ] } {
- message "Building [file tail $dir] index╔"
-
- # if the '[incr tcl]' version exists, use that
- # use 'catch' also in case directory is write-protected
- if [catch { itcl_mkindex : *.*tcl } ] {
- # else try the normal one
- catch { auto_mkindex : *.*tcl }
- }
- }
- }
- }
- # redo the auto-mode-file connections (see "smarterSource.tcl")
- message "Building the mode-file dependency array"
- catch {autoModeFiles}
- message ""
- cd $d
- }
-
-
- proc tclMenuProc {menu item} {
- global tclColoring
-
- eval $item
- }
-
-
- #===========================================================================
- # Debug a Tcl procedure.
- #===========================================================================
-
- # Alpha TCL programming mode
-
- proc traceTclProc {} {
- global tclMenu
- if {[llength [traceFunc status]]>2} {
- catch {markMenuItem $tclMenu {traceTclProc╔} off}
- catch {enableMenuItem $tclMenu dumpTraces off}
- if {[string length [set data [traceDump]]]} {
- if {[askyesno "Dump traces?"] == "yes"} {
- dumpTraces [string trimright [lindex [traceFunc status] 3] {,}] $data
- setWinInfo dirty 0
- }
- }
- traceFunc off
- message "Tracing off."
- return
- }
- if {[llength [winNames]] && [string length [set sel [getSelect]]]} {
- set func [listpick -L $sel -p {Func Name:} [lsort -ignore [info procs]]]
- } else {
- set func [listpick -p {Func Name:} [lsort -ignore [info procs]]]
- }
- if {![string length $func]} return
- traceFunc on $func ""
- catch {markMenuItem $tclMenu {traceTclProc╔} on}
- catch {enableMenuItem $tclMenu dumpTraces on}
- message "Tracing '$func'╔"
- }
-
-
- proc dumpTraces {{name ""} {data ""}} {
- if {![string length $name]} {
- set name [string trimright [lindex [traceFunc status] 3] {,}]
- }
- if {![string length $data]} {
- set data [traceDump]
- }
-
- if {![string length $data]} {
- message "Trace buffer empty"
- } else {
- new -n "* Trace '$name' *"
- insertText $data
- setWinInfo dirty 0
- goto 0
- }
- }
-
- proc setTclMode {} {
- changeMode "Tcl"
- }
-
- #================================================================================
- proc TclMarkFile {} {
- set end [maxPos]
- set pos 0
- set l {}
- set markExpr {^[ \t]*(itcl_class|proc|method)}
- set class ""
- while {![catch {search -s -f 1 -r 1 -m 0 -i 0 "$markExpr" $pos} res]} {
- set start [lindex $res 0]
- set end [nextLineStart $start]
- set t [getText $start $end]
- switch [lindex $t 0] {
- "proc" { set text [lindex $t 1] }
- "method" { set text ${class}::[lindex $t 1] }
- "itcl_class" {
- set class [lindex $t 1]
- set text "${class} 000"
- }
- }
- set pos $end
- set inds($text) [lineStart [expr $start - 1]]
- }
-
- set already ""
-
- if {[info exists inds]} {
- foreach f [lsort -ignore [array names inds]] {
- set next [nextLineStart $inds($f)]
- if { [string first "::" $f] != -1 } {
- set ff " :: [lindex [split $f "::"] 2]"
- } elseif { [string first "000" $f] != -1 } {
- set ff "Class '[lindex $f 0]'"
- } else {
- set ff $f
- }
- while { [lsearch -exact $already $ff] != -1 } {
- set ff "$ff "
- }
- lappend already $ff
- setNamedMark $ff $inds($f) $next $next
- }
- }
- }
-
- proc dummyTcl {} {}
-
- #===============================================================================
- proc TclDblClick {from to shift option control} {
- global HOME auto_index
-
- select $from $to
- set text [getSelect]
-
- # Is it a loaded proc?
- if {[info exists "auto_index($text)"]} {
- editMark "$auto_index($text)" $text
- return
- }
- # Is it a built-in Alpha command?
- set lines [grep "^Ñ $text " "$HOME:Help:Alpha Commands"]
- if {[string length $lines]} {
- editMark "$HOME:Help:Alpha Commands" $text
- setWinInfo read-only 1
- return
- }
- # Is it a core Tcl command?
- set lines [grep "^ $text -" "$HOME:Help:Tcl Commands"]
- if {[string length $lines]} {
- editMark "$HOME:Help:Tcl Commands" $text
- setWinInfo read-only 1
- return
- }
- # Is it a global variable?
- if {[llength [info globals [string trimleft $text {$}]]]==1} {
- showVarValue [string trimleft $text {$}]
- return
- }
- message "No docs $shift $control $option"
- }
-
- proc procDefinition {} {
- global auto_index auto_help
-
- if {[llength [winNames]] && [string length [set sel [getSelect]]]} {
- set func [listpick -L $sel -p {Proc?} [lsort -ignore [array names auto_index]]]
- } else {
- set func [listpick -p {Proc?} [lsort -ignore [array names auto_index]]]
- }
-
- editMark "$auto_index($func)" $func
- }
-
- #===============================================================================
-